﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Bindable.Linq.SampleApplication.Resources.ContactTemplateResources"
    xmlns:test="clr-namespace:Bindable.Linq.SampleApplication"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Resources/BrushResources.xaml" />
        <ResourceDictionary Source="/Resources/ConverterResources.xaml" />
        <ResourceDictionary Source="/Resources/ImageResources.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate x:Key="ContactTemplate_EditableContactDataTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Foreground="#444444" Text="{Binding Path=Name}" />
            <TextBox Grid.Column="1" Foreground="#444444" Text="{Binding Path=Company}" />
        </Grid>
    </DataTemplate>
    
    <DataTemplate x:Key="ContactTemplate_ReadOnlyContactDataTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" FontWeight="Bold" Foreground="#444444" Text="{Binding Path=Name}" />
            <TextBlock Grid.Column="1" Foreground="#444444" Text="{Binding Path=EmailAddress}" />
        </Grid>
    </DataTemplate>

    <Style x:Key="ContactTemplate_DeleteButtonStyle" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border>
                        <ContentPresenter />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
	
    <Style x:Key="ContactTemplate_EditableContactListBoxItemStyle" TargetType="ListBoxItem">
        <Setter Property="Opacity" Value="1" />
        <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Continue" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border 
                        Background="Transparent"
                        BorderThickness="1"
                        CornerRadius="7"
                        Padding="10,0,0,0"
                        SnapsToDevicePixels="True"
                        x:Name="_border"
                        Cursor="Hand"
                        Margin="7"
                        Height="60"
                        >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="32" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Button
                                Grid.Column="0"
                                Margin="0,0,7,0"
                                Style="{StaticResource ContactTemplate_DeleteButtonStyle}"
                                Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsMouseOver, Converter={StaticResource Converter_BooleanToVisibilityConverter}}"
                                Command="test:Commands.Delete"
                                CommandParameter="{Binding }"
                                >
                                <Rectangle Width="25" Height="25" Fill="{StaticResource Image_Delete}" />
                            </Button>

                            <ContentPresenter
                                Grid.Column="1"
                                VerticalAlignment="Center"
                                />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="_border" Property="Background" Value="{StaticResource Brush_LightOrange}" />
                            <Setter TargetName="_border" Property="BorderBrush" Value="#FFC587" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True" />
                                <Condition Property="Selector.IsSelectionActive" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="_border" Property="Background" Value="{StaticResource Brush_DarkOrange}" />
                            <Setter TargetName="_border" Property="BorderBrush" Value="#FFAD49" />
                        </MultiTrigger>
                        <!--<EventTrigger RoutedEvent="ListBoxItem.Loaded">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetProperty="Opacity"
                                        From="0"
                                        To="1"
                                        Duration="0:0:0.3"
                                        />
                                    <DoubleAnimation
                                        Storyboard.TargetProperty="Height"
                                        Storyboard.TargetName="_border"
                                        From="0"
                                        To="75"
                                        Duration="0:0:0.3"
                                        />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ContactTemplate_ReadOnlyContactListBoxItemStyle" TargetType="ListBoxItem">
        <Setter Property="Opacity" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border 
                        Background="Transparent"
                        BorderThickness="1"
                        CornerRadius="7"
                        Padding="14"
                        SnapsToDevicePixels="True"
                        x:Name="_border"
                        Cursor="Hand"
                        Margin="7"
                        Height="50"
                        >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="32" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Button
                                Grid.Column="0"
                                Margin="0,0,7,0"
                                Style="{StaticResource ContactTemplate_DeleteButtonStyle}"
                                Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsMouseOver, Converter={StaticResource Converter_BooleanToVisibilityConverter}}"
                                Command="test:Commands.Delete"
                                CommandParameter="{Binding Original}"
                                >
                                <Rectangle Width="25" Height="25" Fill="{StaticResource Image_Delete}" />
                            </Button>

                            <ContentPresenter
                                Grid.Column="1"
                                VerticalAlignment="Center"
                                />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="_border" Property="Background" Value="{StaticResource Brush_LightOrange}" />
                            <Setter TargetName="_border" Property="BorderBrush" Value="#FFC587" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True" />
                                <Condition Property="Selector.IsSelectionActive" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="_border" Property="Background" Value="{StaticResource Brush_DarkOrange}" />
                            <Setter TargetName="_border" Property="BorderBrush" Value="#FFAD49" />
                        </MultiTrigger>
                        <!--<EventTrigger RoutedEvent="ListBoxItem.Loaded">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation
                                        Storyboard.TargetProperty="Opacity"
                                        From="0"
                                        To="1"
                                        Duration="0:0:0.3"
                                        />
                                    <DoubleAnimation
                                        Storyboard.TargetProperty="Height"
                                        Storyboard.TargetName="_border"
                                        From="0"
                                        To="60"
                                        Duration="0:0:0.3"
                                        />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger> -->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style x:Key="ContactTemplate_EditableListBoxStyle" TargetType="ListBox">
        <Setter Property="ItemTemplate" Value="{StaticResource ContactTemplate_EditableContactDataTemplate}" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource ContactTemplate_EditableContactListBoxItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <ScrollViewer>
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ContactTemplate_ListBoxStyle" TargetType="ListBox">
        <Setter Property="ItemTemplate" Value="{StaticResource ContactTemplate_ReadOnlyContactDataTemplate}" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource ContactTemplate_ReadOnlyContactListBoxItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <ScrollViewer>
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>